﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YogaStudio.Data.Domain;
using YogaStudio.Service.BLL;

namespace YogaStudio.WebUI.Models
{
    public class FacultyController : Controller
    {
        IFacultyService facultyService = new FacultyService();
        Faculty _currentFaculty;
        public Faculty CurrentFaculty
        {
            get
            {
                return _currentFaculty ?? (_currentFaculty = facultyService.GetFacultyByLogInUserName(User.Identity.Name));
            }
        }

        [Authorize(Roles="Faculty")]
        public ActionResult Index()
        {
            ViewBag.FacultyFullName = CurrentFaculty == null ? "Unknown" : CurrentFaculty.FullName;
            return View();
        }


        [Authorize(Roles = "Faculty")]
        public ActionResult ViewAdvisees()
        {
            ViewBag.FacultyFullName = CurrentFaculty == null ? "Unknown" : CurrentFaculty.FullName;
            return View();
        }

        [Authorize(Roles="Faculty, Admin")]
        public ActionResult _Advisees()
        {
            if (CurrentFaculty == null)
            {
                var allAdvisees = facultyService.GetAllAdvisees();
                return View(allAdvisees);
            }
            var advisees = facultyService.GetAdviseesByFacultyId(CurrentFaculty.Id);
            return PartialView(advisees);
        }
        protected override void Dispose(bool disposing)
        {
            facultyService.Dispose(disposing);
            base.Dispose(disposing);
        }
    }
}